package receiver;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestBuffer {

	
	
	@Test
	public void testInserer() {
		Buffer b = new Buffer();
		b.inserer("Acram travaille", 0);
	
		assertEquals(b.getContenu(), "Acram travaille");
		assertTrue(b.getContenu().length() == 15);
		try{
			b.inserer("à CAP", 17);
			System.out.println(b.getContenu());
			fail("ce blic ne doit pas etres executé");
			
		}
		catch (IndexOutOfBoundsException e){
		
		}
	}
	
	
	@Test
	public void testGetContenu() {
		Buffer b = new Buffer();
		try{
			b.getContenu(0, 5);
			fail("erreur");
		}
		catch(IndexOutOfBoundsException e){}
		b.inserer("un element", 0);
		assertEquals(b.getContenu(0, 2), "un");
		try{
			b.getContenu(5, 0);
			fail("erreur");
		}
		catch(IndexOutOfBoundsException e){} 
		
		try{
			b.getContenu(-2, 3);
			fail("erreur");
		}
		catch(IndexOutOfBoundsException e){} 
		
		try{
			b.getContenu(2, -3);
			fail("erreur");
		}
		catch(IndexOutOfBoundsException e){}
		
	}

	@Test
	public void testEffacer() {
		Buffer b = new Buffer();
		b.inserer("une chaine de caractere", 0);
		b.effacer(0, 0);
		assertEquals(b.getContenu(), "une chaine de caractere");
		b.effacer(4, 10);
		assertEquals(b.getContenu(), "une  de caractere");
	}
	
	@Test
	public void testClone() throws CloneNotSupportedException{
		Buffer b = new Buffer();
		b.inserer("une chaine de caractere", 0);
		b.effacer(0, 0);
		assertEquals(b.getContenu(), "une chaine de caractere");
		b.effacer(4, 10);
		assertEquals(b.getContenu(), "une  de caractere");
		
		Buffer nouveauBuffer = (Buffer) b.clone();
		nouveauBuffer.inserer("chaine", 4);
		assertFalse(nouveauBuffer.getContenu() == b.getContenu());
	}



}
